
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<%@ page contentType="text/html; charset=utf-8"%>
	<%@ include file="/commons/taglibs.jsp"%>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>增加应用</title>
		<%@ include file="/commons/css_js_head.jsp"%>
<script type="text/javascript" src="${ctx }/js/cascadeConnectionMenu.js"></script>
<script type="text/javascript" src="${ctx }/js/xindiqu.js"></script>
<script type="text/javascript">
	
	window.onload=function(){//页面加载完毕后执行此方法
	//初始化各级联菜单，setDefaultAreaCode方法通过地区码参数指定默认显示的地区
	
	var dq = document.getElementById("appServer_dqM").value;
	new CascadeConnectionMenu().setDefaultAreaCode(dq).//默认显示"越秀区",
											initByArray('appServer.selA',//内容为省的select元素的name（字符串）或id值
											shengArray,//内容为所有省的数组对象
											'appServer.selB',//内容为市的select元素的name（字符串）或id值
											shiArray,//内容为所有市的数组对象
											'appServer.selC',//内容为区的select元素的name（字符串）或id值
											quArray);//内容为所有区的数组对象
	}
		
</script>
<script type="text/javascript">

//复写Url
doSaveUrl = "${ctx }/base/appServerAction!doSave.ts";
doReturnUrl = "${ctx }/base/appServerAction!doList.ts";



//验证厂家编号
function checkCompCode() {

	var appcompCode = document.getElementById("appServer.compCode");
	var compCode = document.getElementById("compCode");
	
	if(appcompCode.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入厂家编号！<\/span>";
		cleanData(appcompCode,compCode,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(compCode,innerHtml);
		return true;
	}
}

//验证厂家随机编码
function checkCompRandom() {

	var userName = document.getElementById("appServer.compRandom");
	var compRandom = document.getElementById("compRandom");
	
	if(userName.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入厂家随机编码！<\/span>";
		cleanData(userName,compRandom,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(compRandom,innerHtml);
		return true;
	}
}

//验证机器码
function checkDeviceCode() {

	var appdeviceCode = document.getElementById("appServer.deviceCode");
	var deviceCode = document.getElementById("deviceCode");
	
	if(appdeviceCode.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入机器码！<\/span>";
		cleanData(deviceCode,deviceCode,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(deviceCode,innerHtml);
		return true;
	}
}



//验证随机机器码
function checkDeviceRandom() {

	var appdeviceRandom = document.getElementById("appServer.deviceRandom");
	var deviceRandom = document.getElementById("deviceRandom");
	
	if(appdeviceRandom.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入机器随机码！<\/span>";
		cleanData(appdeviceRandom,deviceRandom,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(deviceRandom,innerHtml);
		return true;
	}
}



//验证应用名称
function checkName() {

	var appname = document.getElementById("appServer.name");
	var name = document.getElementById("name");
	
	if(appname.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入应用名称！<\/span>";
		cleanData(appname,name,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(name,innerHtml);
		return true;
	}
}


//验证IP地址
function checkIpAddress() {

	var appipAddress = document.getElementById("appServer.ipAddress");
	var ipAddress = document.getElementById("ipAddress");
	var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/; //验证Ip的正则表达式
	
	
	
	
	if(appipAddress.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入IP地址！<\/span>";
		cleanData(appipAddress,ipAddress,innerHtml);
		return false;
	}else if(!appipAddress.value.match(reg)){
		var innerHtml = "<span class='ts_red'>输入的IP地址不正确！<\/span>";
		ipAddress.innerHTML = innerHtml;
		//cleanData(appipAddress,ipAddress,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(ipAddress,innerHtml);
		//return true;
	}
	isExist()
}

//验证端口
function checkPort() {

	var appPort = document.getElementById("appServer.port");
	var port = document.getElementById("port");
	var reg = /^[1-9][0-9]{0,4}$/;
	
	if(appPort.value.replace(/(^\s*)|(\s*$)/g,"")==""){
		var innerHtml = "<span class='ts_red'>请输入端口！<\/span>";
		cleanData(appPort,port,innerHtml);
		return false;
	}else if(!appPort.value.match(reg)){
		var innerHtml = "<span class='ts_red'>请输正确的端口！<\/span>";
		port.innerHTML = innerHtml;
		//cleanData(appPort,port,innerHtml);
		return false;
	}else{
		var innerHtml = "<span class='ts_green'>验证通过！<\/span>";
		disInfo(port,innerHtml);
		//return true;
	}
	isExist()
}


//验证IP地址和端口是否已经被占用
function isExist(){
		var appipAddress = document.getElementById("appServer.ipAddress");
		var appPort = document.getElementById("appServer.port");
		if(
			appipAddress.value.replace(/(^\s*)|(\s*$)/g,"")!="" &&
			appPort.value.replace(/(^\s*)|(\s*$)/g,"")!=""
		){
			$.ajax({
      type : "post",
      url : "${ctx }/base/appServerAction!doCheckPortAndIPIsExist.ts",
      cache: false,
      data : "&IP="+appipAddress.value+"&port="+appPort.value,
      success : function(data){
      
      if( data == "true" )
       {
           var innerHtml = "<span class='ts_red'>该IP地址和端口已经被占用，请重新输入！<\/span>";
           mesg.innerHTML=innerHtml;
          $("#confirmBtn").attr('disabled', true);
          
           return false;
        }
       else
       {
           var innerHtml = "<span class='ts_green'><\/span>";
           mesg.innerHTML=innerHtml;
           $("#confirmBtn").attr('disabled', false);
          return true;
       }
      },
     error: function(){
     	   var innerHtml = "<span class='ts_red'>服务繁忙，请稍后再试！<\/span>";
           mesg.innerHTML=innerHtml;
           //txtObj.value = "";
           return false;
     	}
   });
		}
}



function checkForm(){
	
	var appipAddress = document.getElementById("appServer.interAddress");
	var appPort = document.getElementById("appServer.interType");
	var appname = document.getElementById("appServer.name");
	
	if(appipAddress.value.replace(/(^\s*)|(\s*$)/g,"")!="" && appPort.value.replace(/(^\s*)|(\s*$)/g,"")!="" && appname.value.replace(/(^\s*)|(\s*$)/g,"")!=""){
		return true;
	}else{
		alert("带*号的内容不能为空！");
		return false;
	}
}

//保存
function doSave() {
	var _form = document.forms[0];
	if (doSaveUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}
	if(checkForm()){
		
		_form.action = doSaveUrl;
		_form.submit();
	}
}
//验证名称是否存在
function checkUseName()
{
   var name=document.getElementById("applename");
   var userMachineType=document.getElementById("name");
   
   if(name.value == ""){
		var innerHtml = "<span class='ts_red'>请输入名称！<\/span>";
		getFocus(name,userMachineType,innerHtml);
		return false;
	}else{
		$.ajax({
	   		type:"post",
	   		url:"${ctx }/base/appServerAction!checkName.ts",
	   		cache:false,
	   		data:"&name="+name.value,
	   		success:function(data){
	   			if(data=="true"){
	   				var innerHtml="<span class='ts_red'>该应用名称已存在，请重新输入！<\/span>";
	   				userMachineType.innerHTML=innerHtml;
	   				name.value ="";
	   				name.focus();
	   				return false;
	   			}else{
	   				var innerHtml = "<span class='ts_green'>验证通过，该应用名称可以使用！<\/span>";
	           		userMachineType.innerHTML=innerHtml;
	           		return true;
	   			}
	   		},
	   		error:function(){
	   		    var innerHtml = "<span class='ts_red'>服务繁忙，请稍后再试！<\/span>";
	            userMachineType.innerHTML=innerHtml;
	            name.value = "";
	            return false;
	   		}
   		});
	}
}
</script>
	</head>

	<body style="overflow-x: hidden">
		<div class="mTitle">
			<span class="hidsearch"></span>
			<b class="bbig">增加应用</b> 带
			<b class="fred"> * </b>号为必填项
		</div>

		<form action="/base/appServerAction" method="post">
		<s:hidden name="appServer.dqM"></s:hidden>
			<!--list -->
			<div class="mainAdd">
				<table class="addTable">

					

					<tr>
						<td colspan="4">
							<b class="fblue">应用平台信息</b>
							<!-- 提示IP和端口是否已经被占用 -->
							<span id="mesg"></span>
						</td>
					</tr>
					<%-- 
					<tr>
						<th>
							<b class="fred"> * </b> 厂家编码：
						</th>
						<td>
							<s:textfield name="appServer.compCode" maxlength="16" theme="simple" onblur="checkCompCode()"></s:textfield>
							<span id="compCode"></span>
						</td>
						<th>
							<b class="fred"> * </b> 厂家随机编码：
						</th>
						<td>
							<s:textfield name="appServer.compRandom" maxlength="16" theme="simple" onblur="checkCompRandom()"></s:textfield>
							<span id="compRandom"></span>
						</td>
					</tr>
					
					<tr>
						<th>
							<b class="fred"> * </b> 机器码：
						</th>
						<td>
							<s:textfield name="appServer.deviceCode" maxlength="16" theme="simple" onblur="checkDeviceCode()"></s:textfield>
							<span id="deviceCode"></span>
						</td>
							
						<th>
							<b class="fred"> * </b> 机器随机码：
						</th>
						<td>
							<s:textfield name="appServer.deviceRandom" maxlength="64" theme="simple" onblur="checkDeviceRandom()"></s:textfield>
							<span id="deviceRandom"></span>
						</td>
					</tr>
					--%>
					<tr>
						<th>
							<b class="fred"> * </b> 应用名称：
						</th>
						<td>
							<s:textfield name="appServer.name" id="applename" maxlength="64" theme="simple" onblur="checkUseName()"></s:textfield>
							<span id="name"></span>
						</td>
						<th>
							<b class="fred"> * </b> 是否上线：
						</th>
						<td>
								<s:select list="#{1:'是',0:'否'}" 
							theme="simple"
                            name="appServer.status" 
						    cssStyle="width:50px;"
							listKey="key" 
							listValue="value"  
							headerKey="0" 
							/> 
						</td>
						
						
					</tr>
					<tr>
						<th>
							<b class="fred"> * </b> 接口类型：
						</th>
						<td  colspan="3">
							<s:select list="#{0:'Socket',1:'Webservice',2:'Http'}" 
							theme="simple"
                            name="appServer.interType" 
						    cssStyle="width:100px;"
							listKey="key" 
							listValue="value"  
							headerKey="0" 
							/> 
							<br/>类型为Socket时，接口地址为IP:端口,接口方法名或参数为空;<br/>类型为Webservice时，接口地址填写URL，接口方法名或参数填入方法;<br/>类型为Http时，接口地址填写URL,接口方名或参数填写参数
						</td>
							
					</tr>
					<tr>
						<th>
							<b class="fred"> * </b> 接口地址：
						</th>
						<td>
							<s:textfield name="appServer.interAddress" maxlength="50" theme="simple" ></s:textfield>
						</td>
							
						<th>
							<b class="fred"> * </b> 接口方法名或参数名：
						</th>
						<td>
							<s:textfield name="appServer.interMethod" maxlength="64" theme="simple" ></s:textfield>
						</td>
					</tr>
					<tr>
						<th width="10%">
							<b class="fred">*</b>区域：
						</th>
						<td width="40%" colspan="3">
						省：<select name="appServer.selA" style="width:140" value="" id="appServer_selA"></select>
 			  市：<select name="appServer.selB" style="width:140" value="" id="appServer.selB"></select>
  			  区：<select name="appServer.selC" style="width:140" value="" id="appServer.selC"></select>
						</td>
					</tr>
					 <tr>	
						<th>
							<b class="fred">  </b> 地址：
						</th>
						<td colspan="3">
							<s:textfield name="appServer.address"  maxlength="500" cssStyle="width:800px;"	 theme="simple"></s:textfield>
							<span id="userMobileInfo"></span>
						</td>
					</tr>
						
					<tr>
						<th>
							<b class="fred">  </b> 备注：
						</th>
						<td colspan="3">
							<s:textfield name="appServer.remark"  maxlength="500" cssStyle="width:800px;"	 theme="simple"></s:textfield>
						</td>
					 </tr>
				</table>
			</div>
			<!--end list -->
			<div class="addToolbar">
				<p>
					<input class="btn" name="btn_confirm" value="确定" type="button" id="confirmBtn"
						onclick="doSave();" />
					<input class="btn" name="btn_return" value="返回" type="button"
						onclick="doReturn();" ; />
				</p>
			</div>

		</form>

	</body>

<script type="text/javascript">
//document.getElementById("appServer.compCode").focus();

document.onkeydown = function(e) {
	if (!e)
		e = window.event;//火狐中是 window.event
	if ((e.keyCode || e.which) == 13) {
		doSave();
	}
}
</script>
</html>
